#include "widget.h"
#include "config.h"

#define AR3PC_VERSION    "V" STRING(ar3pc_VERSION_MAJOR) \
                         "." STRING(ar3pc_VERSION_MINOR) \
                         "." STRING(ar3pc_VERSION_PATCH) \
                         "." STRING(ar3pc_VERSION_TWEAK)

#define font1  QFont("simsun", 10)
#define font2  QFont("simsun", 15)
constexpr int FormWidth = 1024;  // 界面宽度
constexpr int FormHeight = 768;  // 界面高度
constexpr int IntervalY = 20;  // 上下间距
constexpr int WIDTH1 = 20;  // 一个汉字
constexpr int WIDTH2 = 80;  // 编辑框
constexpr int WIDTH3 = 100;  // 大小按钮
constexpr int WIDTH4 = 400;  // 拖动条
constexpr int HEIGHT1 = 20;  // 编辑框,文本
constexpr int HEIGHT2 = 30;  // 小按钮
constexpr int HEIGHT3 = 40;  // 大按钮


/**********************
生成主界面控件
**********************/
void Widget::Init_Mainform()
{
    setFixedSize(FormWidth, FormHeight);
    isSPopen = false;
    int x = FormWidth - 10, y = FormHeight - 30;
    x -= WIDTH3;
    cbbxPort = new QComboBox(this);
    cbbxPort->move(x, y - HEIGHT2 / 2);
    cbbxPort->resize(WIDTH3, HEIGHT2);
    x -= WIDTH1 * 2;
    lbltPort = new QLabel("端口", this);
    lbltPort->move(x, y - HEIGHT1 / 2);
    lbltPort->resize(WIDTH1 * 2, HEIGHT1);
    lbltPort->setFont(font1);
    x -= 10; x -= WIDTH3;
    QStringList Baud;
    Baud << "9600" << "38400" << "115200";
    cbbxBaudrate = new QComboBox(this);
    cbbxBaudrate->move(x, y - HEIGHT2 / 2);
    cbbxBaudrate->resize(WIDTH3, HEIGHT2);
    cbbxBaudrate->addItems(Baud);
    x -= WIDTH1 * 3;
    lbltBaudrate = new QLabel("波特率", this);
    lbltBaudrate->move(x, y - HEIGHT1 / 2);
    lbltBaudrate->resize(WIDTH1 * 3, HEIGHT1);
    lbltBaudrate->setFont(font1);
    x -= 10; x -= WIDTH3;
    btnOpen = new QPushButton("打开连接", this);
    btnOpen->move(x, y - HEIGHT3 / 2);
    btnOpen->resize(WIDTH3, HEIGHT3);
    btnOpen->setFont(font1);
    x -= 10; x -= WIDTH3;
    btnEmergencyStop = new QPushButton("紧急停止", this);
    btnEmergencyStop->move(x, y - HEIGHT3 / 2);
    btnEmergencyStop->resize(WIDTH3, HEIGHT3);
    btnEmergencyStop->setFont(font1);
    x -= 10; x -= WIDTH1;
    ckbxEmergency = new QCheckBox(this);
    ckbxEmergency->move(x, y);
    ckbxEmergency->resize(WIDTH1, HEIGHT1);
    ckbxEmergency->setFont(font1);
    ckbxEmergency->setChecked(true);
    version = "AR3PC ";
    version += AR3PC_VERSION;
    version += " by ZHN  ";
    lblVersion = new QLabel(this);
    lblVersion->setText(version);
    lblVersion->move(10, y - HEIGHT1 / 2);
    lblVersion->resize(x - 20, HEIGHT1);
    lblVersion->setFont(font1);
    tabWedget = new QTabWidget(this);
    tabWedget->move(0, 0);
    tabWedget->resize(FormWidth, FormHeight - HEIGHT3 - 20);
    for (int i = 0; i < TABPAGESNUM; ++i)
        tabPages[i] = new QWidget();
    tabWedget->addTab(tabPages[0], "关节测试");
    tabWedget->addTab(tabPages[1], "参数设置");
    tabWedget->addTab(tabPages[2], "逆运动学");
    tabWedget->addTab(tabPages[3], "图像显示");
    tabWedget->addTab(tabPages[4], "剪贴板");
    tabWedget->addTab(tabPages[5], "波形图");
    // tabWedget->setCurrentIndex(5);
    serialPort = new Protocol(this);
    tmr100ms = new QTimer(this);
    connect(btnOpen, SIGNAL(clicked()), this, SLOT(Slot_btnOpen_Click()));
    connect(btnEmergencyStop, SIGNAL(clicked()), this, SLOT(Slot_btnEmergencyStop_Click()));
    connect(tmr100ms, SIGNAL(timeout()), this, SLOT(Slot_tmr100ms_Tick()));
    tmr100ms->start(100);
}

/**********************
生成标签1控件
**********************/
void Widget::Init_Tab1()
{
    int x = int(20 + WIDTH1 * 4 + WIDTH4 / 2 - WIDTH1 * 1.5);
    int y = int(HEIGHT1 * 1.5 + 10);
    QString JointName;
    ckbx1AutoSend = new QCheckBox("实时发送", tabPages[0]);
    ckbx1AutoSend->move(10, 10);
    ckbx1AutoSend->resize(WIDTH1 * 6, HEIGHT1);
    ckbx1AutoSend->setFont(font1);
    ckbx1AutoSend->setChecked(false);
    lblt1Tuning1 = new QLabel("调节×100", tabPages[0]);
    lblt1Tuning1->move(x, 10);
    lblt1Tuning1->resize(WIDTH1 * 6, int(HEIGHT1 * 1.5));
    lblt1Tuning1->setFont(font2);
    lblt1Tuning2 = new QLabel("调节×10", tabPages[0]);
    lblt1Tuning2->move(750, 10);
    lblt1Tuning2->resize(WIDTH1 * 6, int(HEIGHT1 * 1.5));
    lblt1Tuning2->setFont(font2);
    for (int i = 0; i < 6; ++i) {
        x = 10;
        JointName = "Joint" + QString::number(i + 1);
        lblt1JointName[i] = new QLabel(JointName, tabPages[0]);
        lblt1JointName[i]->move(x, y);
        lblt1JointName[i]->resize(WIDTH1 * 4, int(HEIGHT1 * 1.5));
        lblt1JointName[i]->setFont(font2);
        x += 10; x += WIDTH1 * 4;
        slid1Tuning1[i] = new QSlider(Qt::Horizontal, tabPages[0]);
        slid1Tuning1[i]->move(x, y);
        slid1Tuning1[i]->resize(WIDTH4, HEIGHT2);
        slid1Tuning1[i]->setMaximum(100);
        slid1Tuning1[i]->setObjectName(QString::number(i));
        x += 10; x += WIDTH4;
        lbl1Tuning1[i] = new QLabel(tabPages[0]);
        lbl1Tuning1[i]->move(x, y);
        lbl1Tuning1[i]->resize(WIDTH1 * 3, HEIGHT1);
        lbl1Tuning1[i]->setFont(font2);
        lbl1Tuning1[i]->setText("0");
        connect(slid1Tuning1[i], SIGNAL(valueChanged(int)), lbl1Tuning1[i], SLOT(setNum(int)));
        connect(slid1Tuning1[i], SIGNAL(valueChanged(int)), this, SLOT(Slot_slid1Tuning_valueChanged()));
        x += 10; x += WIDTH1 * 1.5;
        slid1Tuning2[i] = new QSlider(Qt::Horizontal, tabPages[0]);
        slid1Tuning2[i]->move(x, y);
        slid1Tuning2[i]->resize(WIDTH4, HEIGHT2);
        slid1Tuning2[i]->setMaximum(100);
        slid1Tuning2[i]->setObjectName(QString::number(i));
        x += 10; x += WIDTH4;
        lbl1Tuning2[i] = new QLabel(tabPages[0]);
        lbl1Tuning2[i]->move(x, y);
        lbl1Tuning2[i]->resize(WIDTH1 * 3, HEIGHT1);
        lbl1Tuning2[i]->setFont(font2);
        lbl1Tuning2[i]->setText("0");
        connect(slid1Tuning2[i], SIGNAL(valueChanged(int)), lbl1Tuning2[i], SLOT(setNum(int)));
        connect(slid1Tuning2[i], SIGNAL(valueChanged(int)), this, SLOT(Slot_slid1Tuning_valueChanged()));
        y += HEIGHT2 + IntervalY;
        JointAngleTab1[i] = ar3.NegRadLim[i];
    }
    lblt1Tuning3 = new QLabel("调节×1", tabPages[0]);
    lblt1Tuning3->move(lblt1Tuning1->x(), y);
    lblt1Tuning3->resize(WIDTH1 * 6, int(HEIGHT1 * 1.5));
    lblt1Tuning3->setFont(font2);
    y += HEIGHT1 * 1.5 + 10;
    for (int i = 0; i < 6; ++i) {
        x = 10;
        JointName = "Joint" + QString::number(i + 1);
        lblt1JointName[i + 6] = new QLabel(JointName, tabPages[0]);
        lblt1JointName[i + 6]->move(x, y);
        lblt1JointName[i + 6]->resize(WIDTH1 * 4, int(HEIGHT1 * 1.5));
        lblt1JointName[i + 6]->setFont(font2);
        x += 10; x += WIDTH1 * 4;
        slid1Tuning3[i] = new QSlider(Qt::Horizontal, tabPages[0]);
        slid1Tuning3[i]->move(x, y);
        slid1Tuning3[i]->resize(WIDTH4, HEIGHT2);
        slid1Tuning3[i]->setMaximum(100);
        slid1Tuning3[i]->setObjectName(QString::number(i));
        x += 10; x += WIDTH4;
        lbl1Tuning3[i] = new QLabel(tabPages[0]);
        lbl1Tuning3[i]->move(x, y);
        lbl1Tuning3[i]->resize(WIDTH1 * 3, HEIGHT1);
        lbl1Tuning3[i]->setFont(font2);
        lbl1Tuning3[i]->setText("0");
        connect(slid1Tuning3[i], SIGNAL(valueChanged(int)), lbl1Tuning3[i], SLOT(setNum(int)));
        connect(slid1Tuning3[i], SIGNAL(valueChanged(int)), this, SLOT(Slot_slid1Tuning_valueChanged()));
        x += 0; x += WIDTH1 * 3;
        ledt1PulseTarget[i] = new QLineEdit(tabPages[0]);
        ledt1PulseTarget[i]->move(x, y);
        ledt1PulseTarget[i]->resize(WIDTH2, HEIGHT1);
        ledt1PulseTarget[i]->setFont(font1);
        ledt1PulseTarget[i]->setText("0");
        x += 10; x += WIDTH2;
        lbl1JointAngle[i] = new QLabel(tabPages[0]);
        lbl1JointAngle[i]->move(x, y);
        lbl1JointAngle[i]->resize(WIDTH1 * 4, HEIGHT1);
        lbl1JointAngle[i]->setFont(font1);
        x += 10; x += WIDTH1 * 4;
        lbl1Posture[i] = new QLabel(tabPages[0]);
        lbl1Posture[i]->move(x, y);
        lbl1Posture[i]->resize(WIDTH1 * 4, HEIGHT1);
        lbl1Posture[i]->setFont(font1);
        x += 10; x += WIDTH1 * 4;
        btn1FixLocation[i] = new QPushButton(tabPages[0]);
        btn1FixLocation[i]->move(x, y);
        btn1FixLocation[i]->resize(WIDTH3, HEIGHT2);
        btn1FixLocation[i]->setFont(font1);
        btn1FixLocation[i]->setObjectName(QString::number(i));
        connect(btn1FixLocation[i], SIGNAL(clicked()), this, SLOT(Slot_btn1FixLocation_Click()));
        y += HEIGHT2 + IntervalY;
    }
    btn1FixLocation[0]->setText("复位");
    btn1FixLocation[1]->setText("关节校准");
    btn1FixLocation[2]->setText("工作准备");
    btn1FixLocation[3]->setText("待机");
    btn1FixLocation[4]->setText("收回");
    btn1FixLocation[5]->setText("编辑框");
}

/**********************
生成标签2控件
**********************/
void Widget::Init_Tab2()
{
    int x, x1, x2, y = 10 + HEIGHT2;
    QString JointName;
    for (int i = 0; i < 6; ++i) {
        x = 10;
        JointName = "Joint" + QString::number(i + 1);
        lblt2JointName[i] = new QLabel(JointName, tabPages[1]);
        lblt2JointName[i]->move(x, y);
        lblt2JointName[i]->resize(WIDTH1 * 4, int(HEIGHT1 * 1.5));
        lblt2JointName[i]->setFont(font2);
        x += 10; x += WIDTH1 * 4;
        btn2JointCalibrate[i] = new QPushButton("校准", tabPages[1]);
        btn2JointCalibrate[i]->move(x, y);
        btn2JointCalibrate[i]->resize(WIDTH3, HEIGHT2);
        btn2JointCalibrate[i]->setFont(font1);
        btn2JointCalibrate[i]->setObjectName(QString::number(i + 1));
        connect(btn2JointCalibrate[i], SIGNAL(clicked()), this, SLOT(Slot_btn2JointCalibrate_Click()));
        x += 10; x += WIDTH3;
        ckbx2Reverse[i] = new QCheckBox(tabPages[1]);
        ckbx2Reverse[i]->move(x, y + 5);
        ckbx2Reverse[i]->setObjectName(QString::number(i));
        connect(ckbx2Reverse[i], SIGNAL(clicked()), this, SLOT(Slot_ckbx2Reverse_Click()));
        x += 10; x += WIDTH1;
        lbl2CalibrateFlag[i] = new QLabel("0", tabPages[1]);
        lbl2CalibrateFlag[i]->move(x, y);
        lbl2CalibrateFlag[i]->resize(WIDTH1, HEIGHT1);
        lbl2CalibrateFlag[i]->setFont(font1);
        x += 10; x += WIDTH1;
        btn2ResetStep[i] = new QPushButton("步数复位", tabPages[1]);
        btn2ResetStep[i]->move(x, y);
        btn2ResetStep[i]->resize(WIDTH3, HEIGHT2);
        btn2ResetStep[i]->setFont(font1);
        btn2ResetStep[i]->setObjectName(QString::number(i));
        connect(btn2ResetStep[i], SIGNAL(clicked()), this, SLOT(Slot_btn2ResetStep_Click()));
        x += 10; x += WIDTH3; x1 = x;
        ledt2JointSpeed[i] = new QLineEdit(tabPages[1]);
        ledt2JointSpeed[i]->move(x, y + 5);
        ledt2JointSpeed[i]->resize(WIDTH2, HEIGHT1);
        ledt2JointSpeed[i]->setFont(font1);
        x += 50; x += WIDTH2; x2 = x;
        ledt2JointAccelerate[i] = new QLineEdit(tabPages[1]);
        ledt2JointAccelerate[i]->move(x, y + 5);
        ledt2JointAccelerate[i]->resize(WIDTH2, HEIGHT1);
        ledt2JointAccelerate[i]->setFont(font1);
        x += 50; x += WIDTH2;
        btn2SetParam[i] = new QPushButton(tabPages[1]);
        btn2SetParam[i]->move(x, y);
        btn2SetParam[i]->resize(WIDTH3, HEIGHT2);
        btn2SetParam[i]->setFont(font1);
        x += 10; x += WIDTH3;
        ledt2NegRadLim[i] = new QLineEdit(tabPages[1]);
        ledt2NegRadLim[i]->move(x, y + 5);
        ledt2NegRadLim[i]->resize(WIDTH2, HEIGHT1);
        ledt2NegRadLim[i]->setFont(font1);
        y += HEIGHT2 + IntervalY;
    }
    btn2SetParam[0]->setText("速度读取");
    btn2SetParam[1]->setText("速度写入");
    btn2SetParam[2]->setText("加速度读取");
    btn2SetParam[3]->setText("加速度写入");
    btn2SetParam[4]->setText("角度下限读取");
    btn2SetParam[5]->setText("角度下限写入");
    connect(btn2SetParam[0], SIGNAL(clicked()), this, SLOT(Slot_btn2ReadSpeData_Click()));
    connect(btn2SetParam[1], SIGNAL(clicked()), this, SLOT(Slot_btn2WriteSpeData_Click()));
    connect(btn2SetParam[2], SIGNAL(clicked()), this, SLOT(Slot_btn2ReadAccData_Click()));
    connect(btn2SetParam[3], SIGNAL(clicked()), this, SLOT(Slot_btn2WriteAccData_Click()));
    connect(btn2SetParam[4], SIGNAL(clicked()), this, SLOT(Slot_btn2ReadNegRadLim_Click()));
    connect(btn2SetParam[5], SIGNAL(clicked()), this, SLOT(Slot_btn2WriteNegRadLim_Click()));
    x = 10;
    btn2JointCalibrate[6] = new QPushButton("一键校准", tabPages[1]);
    btn2JointCalibrate[6]->move(x, y);
    btn2JointCalibrate[6]->resize(WIDTH3, HEIGHT2);
    btn2JointCalibrate[6]->setFont(font1);
    btn2JointCalibrate[6]->setObjectName("0");
    connect(btn2JointCalibrate[6], SIGNAL(clicked()), this, SLOT(Slot_btn2JointCalibrate_Click()));
    x += 10; x += WIDTH3;
    btn2JointCalibrate[7] = new QPushButton("清空校准", tabPages[1]);
    btn2JointCalibrate[7]->move(x, y);
    btn2JointCalibrate[7]->resize(WIDTH3, HEIGHT2);
    btn2JointCalibrate[7]->setFont(font1);
    btn2JointCalibrate[7]->setObjectName("7");
    connect(btn2JointCalibrate[7], SIGNAL(clicked()), this, SLOT(Slot_btn2JointCalibrate_Click()));
    x += 10; x += WIDTH3;
    btn2ResetStep[6] = new QPushButton("全部复位", tabPages[1]);
    btn2ResetStep[6]->move(x, y);
    btn2ResetStep[6]->resize(WIDTH3, HEIGHT2);
    btn2ResetStep[6]->setFont(font1);
    btn2ResetStep[6]->setObjectName(QString::number(6));
    connect(btn2ResetStep[6], SIGNAL(clicked()), this, SLOT(Slot_btn2ResetStep_Click()));
    x += 10; x += WIDTH3;
    btn2ReverseStep = new QPushButton("编辑框取负", tabPages[1]);
    btn2ReverseStep->move(x, y);
    btn2ReverseStep->resize(WIDTH3, HEIGHT2);
    btn2ReverseStep->setFont(font1);
    btn2ReverseStep->setObjectName(QString::number(6));
    connect(btn2ReverseStep, SIGNAL(clicked()), this, SLOT(Slot_btn2ReverseStep_Click()));
    lblt2Speed = new QLabel("速度", tabPages[1]);
    lblt2Speed->move(x1, 10);
    lblt2Speed->resize(WIDTH1 * 6, HEIGHT2);
    lblt2Speed->setFont(font2);
    lblt2Accelerate = new QLabel("加速度", tabPages[1]);
    lblt2Accelerate->move(x2, 10);
    lblt2Accelerate->resize(int(WIDTH1 * 7.5), HEIGHT2);
    lblt2Accelerate->setFont(font2);
}

/**********************
生成标签3控件
**********************/
void Widget::Init_Tab3()
{
    int x = 10, y = 10;
    for (int i=0; i<4; ++i){
        ckbx3Options[i] = new QCheckBox(tabPages[2]);
        ckbx3Options[i]->move(x, y);
        ckbx3Options[i]->resize(WIDTH1 * 6, HEIGHT1);
        ckbx3Options[i]->setFont(font1);
        x += 10; x += WIDTH1 * 6;
    }
    ckbx3Options[0]->setText("安全检查");
    ckbx3Options[1]->setText("保存数据");
    ckbx3Options[2]->setText("关节6自由");
    ckbx3Options[3]->setText("轨迹规划");
    y += 10; y += HEIGHT1;
    for (int i = 0; i < 6; ++i) {
        x = 10;
        lblt3Posture[i] = new QLabel(tabPages[2]);
        lblt3Posture[i]->move(x, y);
        lblt3Posture[i]->resize(WIDTH1 * 4, HEIGHT2);
        lblt3Posture[i]->setFont(font2);
        x += 10; x += WIDTH1 * 4;
        btn3PostureDeltaPlus[i] = new QPushButton("+", tabPages[2]);
        btn3PostureDeltaPlus[i]->move(x, y);
        btn3PostureDeltaPlus[i]->resize(WIDTH1, HEIGHT1);
        btn3PostureDeltaPlus[i]->setFont(font1);
        btn3PostureDeltaPlus[i]->setObjectName(QString::number(i));
        connect(btn3PostureDeltaPlus[i], SIGNAL(clicked()), this, SLOT(Slot_btn3PostureDelta_Click()));
        x += 10; x += WIDTH1;
        btn3PostureDeltaMinus[i] = new QPushButton("-", tabPages[2]);
        btn3PostureDeltaMinus[i]->move(x, y);
        btn3PostureDeltaMinus[i]->resize(WIDTH1, HEIGHT1);
        btn3PostureDeltaMinus[i]->setFont(font1);
        btn3PostureDeltaMinus[i]->setObjectName(QString::number(i+6));
        connect(btn3PostureDeltaMinus[i], SIGNAL(clicked()), this, SLOT(Slot_btn3PostureDelta_Click()));
        x += 10; x += WIDTH1;
        ledt3PostureDeltaValue[i] = new QLineEdit(tabPages[2]);
        ledt3PostureDeltaValue[i]->move(x, y);
        ledt3PostureDeltaValue[i]->resize(WIDTH2, HEIGHT1);
        ledt3PostureDeltaValue[i]->setFont(font1);
        x += 10; x += WIDTH2;
        ledt3Posture[i] = new QLineEdit(tabPages[2]);
        ledt3Posture[i]->move(x, y);
        ledt3Posture[i]->resize(WIDTH2, HEIGHT1);
        ledt3Posture[i]->setFont(font1);
        x += 10; x += WIDTH4;
        btn3PulseDeltaPlus[i] = new QPushButton("+", tabPages[2]);
        btn3PulseDeltaPlus[i]->move(x, y);
        btn3PulseDeltaPlus[i]->resize(WIDTH1, HEIGHT1);
        btn3PulseDeltaPlus[i]->setFont(font1);
        btn3PulseDeltaPlus[i]->setObjectName(QString::number(i));
        connect(btn3PulseDeltaPlus[i], SIGNAL(clicked()), this, SLOT(Slot_btn3PulseDelta_Click()));
        x += 10; x += WIDTH1;
        btn3PulseDeltaMinus[i] = new QPushButton("-", tabPages[2]);
        btn3PulseDeltaMinus[i]->move(x, y);
        btn3PulseDeltaMinus[i]->resize(WIDTH1, HEIGHT1);
        btn3PulseDeltaMinus[i]->setFont(font1);
        btn3PulseDeltaMinus[i]->setObjectName(QString::number(i+6));
        connect(btn3PulseDeltaMinus[i], SIGNAL(clicked()), this, SLOT(Slot_btn3PulseDelta_Click()));
        x += 10; x += WIDTH1;
        ledt3PulseDeltaValue[i] = new QLineEdit(tabPages[2]);
        ledt3PulseDeltaValue[i]->move(x, y);
        ledt3PulseDeltaValue[i]->resize(WIDTH2, HEIGHT1);
        ledt3PulseDeltaValue[i]->setFont(font1);
        y += HEIGHT2 + IntervalY;
    }
    lblt3Posture[0]->setText("X");
    lblt3Posture[1]->setText("Y");
    lblt3Posture[2]->setText("Z");
    lblt3Posture[3]->setText("ROL");
    lblt3Posture[4]->setText("PIT");
    lblt3Posture[5]->setText("YAW");
    x = 10;
    btn3PostureDeltaPlus6 = new QPushButton("+", tabPages[2]);
    btn3PostureDeltaPlus6->move(x, y);
    btn3PostureDeltaPlus6->resize(WIDTH2, HEIGHT2);
    btn3PostureDeltaPlus6->setFont(font1);
    connect(btn3PostureDeltaPlus6, SIGNAL(clicked()), this, SLOT(Slot_btn3PostureDeltaPlus6_Click()));
    x += 10; x += WIDTH2;
    btn3PostureDeltaMinus6 = new QPushButton("-", tabPages[2]);
    btn3PostureDeltaMinus6->move(x, y);
    btn3PostureDeltaMinus6->resize(WIDTH2, HEIGHT2);
    btn3PostureDeltaMinus6->setFont(font1);
    connect(btn3PostureDeltaMinus6, SIGNAL(clicked()), this, SLOT(Slot_btn3PostureDeltaMinus6_Click()));
    for (int i = 0; i < 3; ++i) {
        x = 10; y += 10; y += HEIGHT2;
        lblt3Eff[i] = new QLabel(tabPages[2]);
        lblt3Eff[i]->move(x, y);
        lblt3Eff[i]->resize(WIDTH1 * 4, HEIGHT2);
        lblt3Eff[i]->setFont(font2);
        x += 10; x += WIDTH1 * 4;
        ledt3Eff[i] = new QLineEdit(tabPages[2]);
        ledt3Eff[i]->move(x, y);
        ledt3Eff[i]->resize(WIDTH2, HEIGHT1);
        ledt3Eff[i]->setFont(font1);
    }
    lblt3Eff[0]->setText("EffX");
    lblt3Eff[1]->setText("EffY");
    lblt3Eff[2]->setText("EffZ");
    for (int i = 0; i < 6; ++i) {
        ledt3PulseTarget[i] = new QLineEdit(tabPages[2]);
        ledt3PulseTarget[i]->move(ledt1PulseTarget[i]->pos());
        ledt3PulseTarget[i]->resize(WIDTH2, HEIGHT1);
        ledt3PulseTarget[i]->setFont(font1);
        lbl3JointAngle[i] = new QLabel(tabPages[2]);
        lbl3JointAngle[i]->move(lbl1JointAngle[i]->pos());
        lbl3JointAngle[i]->resize(WIDTH1 * 4, HEIGHT1);
        lbl3JointAngle[i]->setFont(font1);
        lbl3Posture[i] = new QLabel(tabPages[2]);
        lbl3Posture[i]->move(lbl1Posture[i]->pos());
        lbl3Posture[i]->resize(WIDTH1 * 4, HEIGHT1);
        lbl3Posture[i]->setFont(font1);
        btn3Options[i] = new QPushButton(tabPages[2]);
        btn3Options[i]->move(btn1FixLocation[i]->pos());
        btn3Options[i]->resize(WIDTH3, HEIGHT2);
        btn3Options[i]->setFont(font1);
    }
    btn3Options[0]->setText("逆解");
    btn3Options[1]->setText("步数同步");
    btn3Options[2]->setText("读取末端点");
    btn3Options[3]->setText("写入末端点");
    connect(btn3Options[0], SIGNAL(clicked()), this, SLOT(Slot_btn3Reverse_Click()));
    connect(btn3Options[1], SIGNAL(clicked()), this, SLOT(Slot_btn3SynchroniseStep_Click()));
    connect(btn3Options[2], SIGNAL(clicked()), this, SLOT(Slot_btn3ReadEff_Click()));
    connect(btn3Options[3], SIGNAL(clicked()), this, SLOT(Slot_btn3WriteEff_Click()));
    for (int i = 0; i < 5; ++i)
        setTabOrder(ledt3Posture[i], ledt3Posture[i+1]);
    setTabOrder(ledt3Posture[5], btn3Options[0]);
    for (int i = 0; i < 5; ++i)
        setTabOrder(btn3Options[i], btn3Options[i+1]);
}

/**********************
生成标签4控件
**********************/
void Widget::Init_Tab4()
{
    int x = 10, y = 10;
    for (int i=0; i<5; ++i){
        ckbx4Options[i] = new QCheckBox(tabPages[3]);
        ckbx4Options[i]->move(x, y);
        ckbx4Options[i]->resize(WIDTH1 * 6, HEIGHT1);
        ckbx4Options[i]->setFont(font1);
        x += 10; x += WIDTH1 * 6;
    }
    ckbx4Options[0]->setText("相机测试");
    ckbx4Options[1]->setText("畸变校正");
    ckbx4Options[2]->setText("匹配图显示");
    ckbx4Options[3]->setText("按压检测");
    ckbx4Options[4]->setText("按压数据写入");
    connect(ckbx4Options[3], SIGNAL(clicked()), this, SLOT(Slot_ckbx4Pressure_Click()));
    connect(ckbx4Options[4], SIGNAL(clicked()), this, SLOT(Slot_ckbx4WriteData_Click()));
    x = 10; y += 10; y += HEIGHT1;
    for (int i=0; i<6; ++i){
        btn4Options[i] = new QPushButton(tabPages[3]);
        btn4Options[i]->move(x, y);
        btn4Options[i]->resize(WIDTH3, HEIGHT2);
        btn4Options[i]->setFont(font1);
        x += 10; x += WIDTH3;
    }
    btn4Options[0]->setText("添加模板");
    btn4Options[1]->setText("3D定位");
    x = 10; y += 50; y += HEIGHT2;
    for (int i=0; i<4; ++i){
        for (int j=0; j<6; ++j){
            btn4UserInterface[i][j] = new QPushButton(tabPages[3]);
            btn4UserInterface[i][j]->move(x, y);
            btn4UserInterface[i][j]->resize(WIDTH3, HEIGHT2);
            btn4UserInterface[i][j]->setFont(font1);
            btn4UserInterface[i][j]->setObjectName(QString::number(i*6+j+1));
            connect(btn4UserInterface[i][j], SIGNAL(clicked()), this, SLOT(Slot_btn4UserInterface_Click()));
            x += 10; x += WIDTH3;
        }
        x = 10; y += 10; y += HEIGHT2;
    }
    btn4UserInterface[0][0]->setText("挂机");
    btn4UserInterface[0][1]->setText("查询");
    btn4UserInterface[0][2]->setText("清除");
    btn4UserInterface[1][4]->setText("核心舱");
    btn4UserInterface[2][3]->setText("实验舱1");
    btn4UserInterface[2][4]->setText("节点舱");
    btn4UserInterface[2][5]->setText("实验舱2");
    btn4UserInterface[3][4]->setText("载人船");
    for (int i=0; i<7; ++i){
        x = 10; y += 10; y += HEIGHT1;
        lblt4Coordinates[i] = new QLabel(tabPages[3]);
        lblt4Coordinates[i]->move(x, y);
        lblt4Coordinates[i]->resize(WIDTH1 * 5, HEIGHT1);
        lblt4Coordinates[i]->setFont(font1);
        x += 10; x += WIDTH1 * 5;
        lbl4Coordinates[i] = new QLabel(tabPages[3]);
        lbl4Coordinates[i]->move(x, y);
        lbl4Coordinates[i]->resize(WIDTH1 * 20, HEIGHT1);
        lbl4Coordinates[i]->setFont(font1);
    }
    lblt4Coordinates[0]->setText("按下:");
    lblt4Coordinates[1]->setText("左图坐标:");
    lblt4Coordinates[2]->setText("右图坐标:");
    lblt4Coordinates[3]->setText("相机坐标:");
    lblt4Coordinates[4]->setText("世界坐标:");
    lblt4Coordinates[5]->setText("光标坐标:");
    lblt4Coordinates[6]->setText("按压力:");
    lbl4Coordinates[6]->setText("0");
#ifdef USE_OPENCV
    connect(ckbx4Options[0], SIGNAL(clicked()), this, SLOT(Slot_ckbx4CameraTest()));
    connect(btn4Options[0], SIGNAL(clicked()), this, SLOT(Slot_btn4AddImageFromFile()));
    connect(btn4Options[1], SIGNAL(clicked()), this, SLOT(Slot_btn4Locate3d()));
#endif
}

/**********************
生成标签5控件
**********************/
void Widget::Init_Tab5()
{
    int x=10, y=10, w, h;
    w = (FormWidth-30)/2;
    h = FormHeight-120 - 3*(10+HEIGHT2);
    tedt5clipboard = new QTextEdit(tabPages[4]);
    tedt5clipboard->move(x, y);
    tedt5clipboard->resize(w, h);
    tedt5clipboard->setFont(font1);
    x += 10; x += w;
    for (int i=0; i<6; ++i){
        ledt5clipboard[i] = new QLineEdit(tabPages[4]);
        ledt5clipboard[i]->move(x, y);
        ledt5clipboard[i]->resize(w, HEIGHT1);
        ledt5clipboard[i]->setFont(font1);
        y += 10; y += HEIGHT1;
    }
    x = 10; y = h + 20;
    for (int i=0; i<3; ++i){
        for (int j=0; j<9; ++j){
            btn5paste[i][j] = new QPushButton(tabPages[4]);
            btn5paste[i][j]->move(x, y);
            btn5paste[i][j]->resize(WIDTH3, HEIGHT2);
            btn5paste[i][j]->setFont(font1);
            btn5paste[i][j]->setObjectName(QString::number(i*9+j));
            connect(btn5paste[i][j], SIGNAL(clicked()), this, SLOT(Slot_btn5Synchronise_Click()));
            x += 10; x += WIDTH3;
        }
        x = 10; y += 10; y += HEIGHT2;
    }
    btn5paste[0][0]->setText("脉冲1复制");
    btn5paste[0][1]->setText("位姿1复制");
    btn5paste[0][2]->setText("角度1复制");
    btn5paste[0][3]->setText("位姿4复制");
    btn5paste[0][4]->setText("脉冲1粘贴");
    btn5paste[0][5]->setText("位姿3粘贴");
    for (int j=0; j<9; ++j){
        btn5paste[1][j]->setText("坐标系"+QString::number(j+1));
        btn5paste[2][j]->setText("自定义"+QString::number(j+1));
    }
}

/**********************
生成标签6控件
**********************/
void Widget::Init_Tab6()
{
#ifdef USE_QTCHART
    line1 = new QLineSeries();
    chart = new QChart();
    QValueAxis *axisX = new QValueAxis;
    QValueAxis *axisY = new QValueAxis;
    axisX->setRange(0,10);
    axisY->setRange(-1, 1);
    chart->addAxis(axisX, Qt::AlignBottom);
    chart->addAxis(axisY, Qt::AlignLeft);
    QChartView* chartview = new QChartView(chart, tabPages[5]);
    chartview->move(0, 0);
    chartview->resize(FormWidth, FormHeight-100);
    for(_t=0;_t<10;_t+=0.1)
        line1->append(_t,sin(_t));
    chart->addSeries(line1);
#endif
}
